package com.google.appengine.a4ieve;

import org.json.JSONArray;
import org.json.JSONObject;

public enum AchievementClass {
    EARNED("earned", "Earned"),
    LOCKED("locked", "Locked"),
    LOCKED_BAD("locked_bad", "Locked Negative");

    private static final JSONArray JSON_REPRESENTATION;

    static {
        JSONArray objects = new JSONArray();
        for (AchievementClass a : values()) {
            JSONObject object = new JSONObject();
            object.put(Const.TYPE, a.classId);
            object.put(Const.NAME, a.screenName);
            objects.put(object);
        }
        JSON_REPRESENTATION = objects;
    }

    private String classId;
    private String screenName;

    AchievementClass(String id, String screenName) {
        this.classId = id;
        this.screenName = screenName;
    }

    public String getClassId() {
        return this.classId;
    }

    public static AchievementClass fromId(String id) {
        for (AchievementClass v : values()) {
            if (v.classId.equals(id)) {
                return v;
            }
        }
        throw new IllegalArgumentException("You passed a wrong list option id");
    }

//    public static String render() {
//        StringBuilder output = new StringBuilder("<span class=\"acheivement-title\">Choose achievement type: " +
//                "</span>&nbsp;<select id=\"type\">");
//        for (AchievementClass achievement : values()) {
//            output.append("<option value=\"").append(achievement.classId).append("\">")
//                    .append(achievement.screenName).append("</option>");
//        }
//        output.append("</select>");
//        return output.toString();
//    }
    public static JSONArray getRepresentation() {
        return JSON_REPRESENTATION;
    }
}
